﻿-- Author      : Kurapica
-- Create Date : 10/22/2008

--[[
    Localization
--]]
do
	-- Check Version
	local version = 1
	if not IGAS:RegisterFile("IGAS.Localization", version) then
		return
	end
	
    -- Scripts
    local _RegisterLocal = {}
    
    local _gameLocale = GetLocale()
    if _gameLocale == "enGB" then
        _gameLocale = "enUS"
    end
    
    -- This metatable is used on all tables returned from GetLocale
    local _metaT = {
        __index = function(self, key)
            rawset(self, key, key)
            return key
        end,
        
        __newindex = function(_table,_key,_value)
            rawset(_table, _key, _value == true and _key or _value)
        end,
    }
    
	local _metaF = {
		__index = {
			["NewLocal"] = function(_key, _locale,_isDefault)
                if _locale and _locale ~= _gameLocale and not _isDefault then
                    return nil
                end
                
                _RegisterLocal[_key] = _RegisterLocal[_key] or setmetatable({}, _metaT)
            
                return _RegisterLocal[_key]
            end,
		},
	
		__newindex = function(_table,_key,_value)
            assert(false)
		end,
	}
    
    IGAS.Localization = setmetatable({}, _metaF)
	
	-- Register Function to IGAS
	IGAS:RegisterFunction("NewLocal", function(self, ...)
		return self.Localization.NewLocal(...)
	end)
end